package com.colin.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

public class CommonUtils {

    public static String getCurrentGitBranch(String directoryPath) {
        String branch = "";
        try {
            ProcessBuilder processBuilder = new ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD");
            processBuilder.directory(new File(directoryPath));
            Process process = processBuilder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            branch = reader.readLine();
        } catch (IOException e) {
            NotificationUtil.error("获取分支异常， msg = " + e.getMessage());
        }
        return branch;
    }

}
